<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="领用科室" prop="kname">
        <el-input
          v-model="queryParams.kname"
          placeholder="请输入领用科室"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="领用耗材" prop="hname">
        <el-input
          v-model="queryParams.hname"
          placeholder="请输入领用耗材"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请人" prop="person">
        <el-input
          v-model="queryParams.person"
          placeholder="请输入申请人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请时间" prop="ltime">
        <el-date-picker clearable
          v-model="queryParams.ltime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择申请时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:apply:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:apply:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:apply:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:apply:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="领用单号" align="center" prop="aid" />
      <el-table-column label="科室编号" align="center" prop="kcode" />
      <el-table-column label="领用科室" align="center" prop="kname" />
      <el-table-column label="申请人" align="center" prop="person" />
      <el-table-column label="申请时间" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetails(scope.row)"
            v-hasPermi="['system:apply:edit']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="审核"
            @click="handleCheck(scope.row)"
          >审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--    选择职位    -->
    <el-dialog :title="title" :visible.sync="open" width="200px" append-to-body>
      <el-radio v-model="radio" label="1">科室库主任</el-radio>
      <el-radio v-model="radio" label="2">中心库主任</el-radio>
      <el-radio v-model="radio" label="3">库房管理员</el-radio>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listApplydan,findList} from "../../../api/system/applydan";
export default {
  name: "record",
  data() {
    return {
      aid: "",
      kcode: null,
      kname: null,
      person: null,
      aid_:null,
      kname_:null,
      person_:null,
      time: null,
      status: null,
      radio: '1',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 医院耗材管理系统表格数据
      applyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        aid: "",
        kname: "",
        person: "",
        assignee:"",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询申请记录列表 */
    getList() {
      this.loading = true;
      listApplydan(this.queryParams).then(response => {
        console.log(response);
        this.applyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    //审核按钮
    handleCheck(row) {
      console.log("审核=>"+row.aid+" "+row.kname+" "+row.person);
      this.aid_ = row.aid;
      this.person_ = row.person;
      this.kname_ = row.kname;
      this.time_ = row.time;
      this.reset();
      this.open = true;
      this.title = "请选择您的身份";
    },    // 表单重置
    reset() {
      this.form = {
        id: null,
        kcode: null,
        kname: null,
        hcode: null,
        hname: null,
        num: null,
        person: null,
        ltime: null,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 提交按钮 */
    submitForm() {
      console.log();
      alert(this.radio);
      let  assignee='';
      if(this.radio=='1'){
        assignee='科室库主任';
        this.queryParams.assignee=assignee;
      }
      if(this.radio=='2'){
        assignee='中心库主任';
        this.queryParams.assignee=assignee;
      }
     if(this.radio=='3'){
        assignee='库房管理员';
       this.queryParams.assignee=assignee;
      }
      alert(assignee);
      console.log(this.aid_+this.kname_+this.person_);
      this.open = false;
      /*this.queryParams.aid=this.aid_;
      this.queryParams.kname=this.kname_;
      this.queryParams.person=this.person_;*/
      findList(assignee).then(response=>{
        console.log(response);
      })
    },
    /** 详情按钮操作 */
    handleDetails(row) {
        console.log(row);
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/apply/export', {
        ...this.queryParams
      }, `apply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
